﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace AAFLogAnalysis
{
    [XmlRoot(ElementName = "settings")]
    public class Setting
    {
        private Setting()
        {
            按简要分组_前N个字符 = 10;
            按简要分组_正则表达式 = @"(?<tz>JS\d+|用户名.*?\s)";
        }
        private static void CtreateInstase()
        {
            if (File.Exists(xmlPath))
            {
                try
                {
                    var fileStream = File.Open(xmlPath, FileMode.Open);
                    XmlSerializer xml = new XmlSerializer(typeof(Setting));
                    _Instase = xml.Deserialize(fileStream) as Setting;
                    fileStream.Dispose();
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.ToString());
                }
            }
            if (_Instase == null)
            {
                _Instase = new Setting();
            }
        }
        public static void Save()
        {
            if (_Instase == null)
                return;
            try
            {
                var fileStream = File.Open(xmlPath, FileMode.OpenOrCreate);
                XmlSerializer xml = new XmlSerializer(typeof(Setting));
                xml.Serialize(fileStream, _Instase);
                fileStream.Dispose();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
        }

        private static string xmlPath = Environment.CurrentDirectory + "\\settings.xml";
        private static Setting _Instase;
        [XmlIgnore]
        public static Setting Instase { get { if (_Instase == null)Setting.CtreateInstase(); return _Instase; } }

        public int 按简要分组_前N个字符 { get; set; }
        public string 按简要分组_正则表达式 { get; set; }
    }
}
